# 指定 CMake 最低版本号
cmake_minimum_required(VERSION 3.0.0)
# 工程信息
project(crypt VERSION 0.1.0)

set(CROSS_COMPILE 0)
IF(CROSS_COMPILE)

# 告知编译器当前要进行交叉编译
set(CMAKE_SYSTEM_NAME linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

# set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
# set(CMAKE_STAGING_PREFIX /home/devel/stage)

# 定义变量交叉编译环境路径
set(tools /opt/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf)
# 指定交叉编译器
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)

# 不在指定目录查找指定工具程序
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# 仅在指定目录查找库文件
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
# 仅在指定目录查找头文件
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

ENDIF(CROSS_COMPILE)

# 添加编译选项
set(CMAKE_C_FLAGS "-g  -Wall -pthread ${CMAKE_C_FLAGS}")

# 相当于一个数组，保存所有相关的目录到变量中
list(APPEND compile_directory_list
    .
    crypt_comm
    aes_crypt
    rsa_crypt
    )
# 头文件路径
include_directories(${compile_directory_list})
# 遍历上面的list表，并将每一个目录下的源文件输出到all_src变量中
foreach(loop_var ${compile_directory_list})
    # message(${loop_var})
    aux_source_directory(${loop_var} all_src)
endforeach(loop_var)

set(TARGET_NAME_CLIENT client)
set(TARGET_NAME_SERVER server)

# 指定生成目标
add_executable(${TARGET_NAME_CLIENT} ${all_src} test/client.c)
add_executable(${TARGET_NAME_SERVER} ${all_src} test/server.c)

file(GLOB_RECURSE openssl_lib "/usr/lib/x86_64-linux-gnu/libcrypto.so" "/usr/lib/x86_64-linux-gnu/libssl.so")
#链接相关库
target_link_libraries(${TARGET_NAME_CLIENT} ${openssl_lib})
target_link_libraries(${TARGET_NAME_SERVER} ${openssl_lib})